// Penanggung Jawab : 
// Nama/Nim  : Alfian Ramadhan / 13509078
// Nama file : playgame.cpp
// Deskripsi : implementasi kelas playgame
 
 #include "playgame.h"
#include <windows.h>
#include <mmsystem.h>

// Konstruktor
PlayGame::PlayGame(){
	// cout<<"playgame dibuat"<<endl;
	
}
PlayGame::PlayGame(const PlayGame&){
	// cout<<"playgame dicopy"<<endl;
}

//Destruktor
PlayGame::~PlayGame(){
	// cout<<" play game destuktor"<<endl;
}

// method-method lain	
void PlayGame::Inisialisasi(){
		// KAMUS
		bool begin; 
		string nama; // tempat penyimpan nama
		
		//ALGORITMA
		begin = true; // boolean penanda permainan interface pertama dimulai

		// untuk keperluan musik
		mciSendString("open 1.mp3 type mpegvideo alias song1",NULL,0,0);
		mciSendString("play song1",NULL,0,0);
		/*mciSendString("open 3.mp3 type mpegvideo alias song2",NULL,0,0);
		mciSendString("open 5.wav type mpegvideo alias song3",NULL,0,0);
		mciSendString("stop song1",NULL,0,0);
		mciSendString("play song3 repeat",NULL,0,0);
		mciSendString("play song3",NULL,0,0);
		*/
		
		while(begin){ 
			system("cls");
			DisplayInterface(); // tampilan interface awal
			cout<<"Pilihan > ";
			Com.BacaCommand(); // membaca masukan user

				if (Com.IsUserNew()){
						nama = Com.ArrayOfCommand[2]; // pengisian masukan nama ke tempat yang sesuai
						cout<< "Permainan dimulai - Inisialisasi dilakukan"<<endl;
						begin = false; // perulangan selesai
						NewData(nama); // keperluan data-data baru
				}
				else if (Com.IsUserLoad()){ // perintah load
						cout<< "Loading Data..."<<endl;
						IO.OpenFarm(&Castro, &time, &area, Com.ArrayOfCommand[2]); // method load data
						begin = false; // perulangan selesai
				}
				else { // selain new dan load
					cout<<"tidak valid... \n"; 
				}
		}
}
void PlayGame::StartGame(){
		bool *game = new bool;
		*game = true;
		DataGame();

	
		while (*game){

			LCD.Go(2,33);
			DisplayGame();

			cout<<endl;
			//cout<<time.GetBencana();
			//LCD.PrintJudul();LCD.PrintUtama();
			HelpNormalMode();
			//time.printWaktu();
			Com.BacaCommand();
			if (IsInRumah()){
					 StartRumah(*game);

			}
			else if (IsInLahan()){
					 StartLahan();
			}
			else if (IsInToko()){
					 StartToko();
			}
		Sleep(200);
		}
	}
void PlayGame::StartRumah(bool &gameplay){ //display rumah belum ada
	
					if (Com.IsUserSave()){
						SavingData();
					}
					else if (Com.IsUserSleep()){
							Sleeping();
								

					}
					else if (Com.IsUserExit()){
							LCD.PrintInfo("Permainan Selesai...");
							LCD.SetWarna(1,15);
							gameplay = false;
					}
					else if (Com.IsUserTeleport()==1){
								LCD.PrintGo(2000);
								Castro.Teleport(1);
					}
					else if (Com.IsUserHelp()){
							LCD.PrintInfo("Anda hanya dapat berpindah ke Lahan");
					}
					
					else if (Com.IsUserArrow()){
								arrowstart();
					}
					
					else {
						GerakBebas();
					}		
			
	}
void PlayGame::StartLahan(){ // display lahan beluma ada
			
			if (Com.IsUserPlow()){
				Plowing();
			}
			else if (Com.IsUserPut()){
				PutOrSell(atoi(Com.ArrayOfCommand[2].c_str()), atoi(Com.ArrayOfCommand[3].c_str()));
			}
			else if (Com.IsUserSlash()){
				Slashing();
			}
			else if (Com.IsUserWater()){
				Watering();
			}
			else if (Com.IsUserHarvest()){
				Harvesting();
			}
			else if (Com.IsUserWakeUp()){
				WakeingUp(atoi(Com.ArrayOfCommand[2].c_str()));
			}
			else if (Com.IsUserSleepKur()){
				SleepKurcaci(atoi(Com.ArrayOfCommand[2].c_str()));
			}
			else if (Com.IsUserStatKur()){
					LCD.PrintInfo("GetStatus...");
					// getstatus kurcaci belum ada
					/*
						mendapatkan status kurcaci
					*/
				}
			else if (Com.IsUserTeleport()==0){
								LCD.PrintGo(2000);
								Castro.Teleport(0);
			}
			else if (Com.IsUserTeleport()==2){
								LCD.PrintGo(2000);
								Castro.Teleport(2);
			}
			else if (Com.IsUserHelp()){
						LCD.PrintInfo("Anda hanya dapat berpindah ke Rumah/Toko");
			}
			else if (Com.IsUserArrow()){
				arrowstart();
			}
			else {
				GerakBebas();
			}
			
	
}
void PlayGame::StartToko(){ // display toko belum ada
			int jumlah =0;
				int barang =0;
				int uang =0;
				int ID =0;
				int slot =0;
				
				if (Com.IsUserSell()){
					Selling(atoi(Com.ArrayOfCommand[2].c_str()), atoi(Com.ArrayOfCommand[3].c_str()));
				}
				else if (Com.IsUserBuy()!=0){  //// ganti jadi ID tanaman, -> boolean
					Buying(Com.IsUserBuy(), atoi(Com.ArrayOfCommand[3].c_str()));
				}
				else if (Com.IsUserStore()){
					ViewStore();
				}
				
				else if (Com.IsUserTeleport() == 1){
									LCD.PrintGo(2000);
									Castro.Teleport(1);
								//else cout<<"Hanya boleh transport ke lahan"<<endl;
					}
					else if (Com.IsUserHelp()){
							LCD.PrintInfo("Anda hanya dapat berpindah ke Lahan");
					}

				else if (Com.IsUserArrow()){
								arrowstart();
								
				}
				else {
					GerakBebas();
					
				}	
	}
void PlayGame::GerakBebas(){ // method untuk mengatasi perintah yang bebas dilakukan dimana saja
		if (Com.IsMoveRight()){
						LCD.PrintInfo("Move Right");
						// set kordinat dan arah hadap
				}
		else if (Com.IsMoveLeft()){
						LCD.PrintInfo("Move Left");
						// set kordinat dan arah hadap
				}
		else if (Com.IsMoveUp()){
						LCD.PrintInfo("Move up");
						// set kordinat dan arah hadap
				}
		else if (Com.IsMoveDown()){
						LCD.PrintInfo("Move down");
						// set kordinat dan arah hadap
				}
		else if (Com.IsUserInventory()){
						//ShowInventory(); belum ada
				}
		else if (Com.IsUserEat()){
					Eating();
		}
		
		else{
			LCD.PrintInfo("perintah tidak valid..");
		}	
	}
void PlayGame::arrowstart(){ // mode arrow, pemain dipersilakan menggunakan arrow pada keyboard
		int ar[8][10];
		int TempX;
		int TempY;
		Point TP1, TP2;
		/*if (Castro.getLocation()==0){
						area.KonvPrint(1,ar);
					}
					else if (Castro.getLocation()==1){
						area.KonvPrint(0,ar);
					}
					else if (Castro.getLocation()==2){
						area.KonvPrint(2,ar);
					}*/
		
		bool arrowmode = true;
		int arrowmotion;
		HelpArrowMode();
		while (arrowmode){
		area.KonvPrint(Castro.getLocation(),ar);
		
			// system("cls");
			// DisplayGame();
			// cout<<endl;
			// //			LCD.PrintJudul();LCD.PrintUtama();
			//time.printWaktu();

			while(!kbhit());
						  arrowmotion = getch();
					
						  if( arrowmotion == '0')
						break;

						if( arrowmotion == 224 ) //whenever an arrow key is pressse my
				 arrowmotion = getch(); //system returns 224 prior to the key val
				 TempX = Castro.getPositionX();
				 TempY = Castro.getPositionY();
			if (arrowmotion ==72){
				if (Castro.getDirection()!=1){
					
					Castro.setDirection(1);

				}
				else {time.penambahWktNormal();
					Castro.setSakaw(Castro.getSakaw()+1);
					if (
						((ar[Castro.getPositionX()+1][Castro.getPositionY()+2] > 0)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()+2] < 4)) ||
						((ar[Castro.getPositionX()+1][Castro.getPositionY()+2] > 7)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()+2] < 10)) ||
						((ar[Castro.getPositionX()+1][Castro.getPositionY()+2] > 15)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()+2] < 19)))	
					{
					Castro.setPosition(Castro.getPositionX(), Castro.getPositionY()+1);
					}

				}
				}
				// set kordinat dan arah hadap
				//pengecekan kordinat di lahan
			else if (arrowmotion==75)
				{
				if (Castro.getDirection()!=2){
					
					Castro.setDirection(2);
				}
				else {		time.penambahWktNormal();
							Castro.setSakaw(Castro.getSakaw()+1);
					if (
						((ar[Castro.getPositionX()][Castro.getPositionY()+1] > 0)  && (ar[Castro.getPositionX()][Castro.getPositionY()+1] < 4)) ||
						((ar[Castro.getPositionX()][Castro.getPositionY()+1] > 7)  && (ar[Castro.getPositionX()][Castro.getPositionY()+1] < 10)) ||
						((ar[Castro.getPositionX()][Castro.getPositionY()+1] > 15)  && (ar[Castro.getPositionX()][Castro.getPositionY()+1] < 19)))
					Castro.setPosition((Castro.getPositionX())-1, Castro.getPositionY());
				}
				}				//set kordinat dan arah hadap
				// pengencekan kordinat di lahan
			else if (arrowmotion==77)
				{
				if (Castro.getDirection()!=3){
					Castro.setDirection(3);
				}
				else {		time.penambahWktNormal();
							Castro.setSakaw(Castro.getSakaw()+1);
					if (
						((ar[Castro.getPositionX()+2][Castro.getPositionY()+1] > 0)  && (ar[Castro.getPositionX()+2][Castro.getPositionY()+1] < 4)) ||
						((ar[Castro.getPositionX()+2][Castro.getPositionY()+1] > 7)  && (ar[Castro.getPositionX()+2][Castro.getPositionY()+1] < 10)) ||
						((ar[Castro.getPositionX()+2][Castro.getPositionY()+1] > 15)  && (ar[Castro.getPositionX()+2][Castro.getPositionY()+1] < 19)))
					Castro.setPosition((Castro.getPositionX())+1, Castro.getPositionY());
				}
				}
				//set kordinat dan arah hadap
				// pengencekan kordinat di lahan
				else if (arrowmotion==80){
				if (Castro.getDirection()!=4){
					Castro.setDirection(4);
				}
				else {		time.penambahWktNormal();
							Castro.setSakaw(Castro.getSakaw()+1);
					if (
						((ar[Castro.getPositionX()+1][Castro.getPositionY()] > 0)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()] < 4)) ||
						((ar[Castro.getPositionX()+1][Castro.getPositionY()] > 7)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()] < 10)) ||
						((ar[Castro.getPositionX()+1][Castro.getPositionY()] > 15)  && (ar[Castro.getPositionX()+1][Castro.getPositionY()] < 19)))
					Castro.setPosition(Castro.getPositionX(), Castro.getPositionY()-1);
				//	LCD.PrintInfoL(area.GetLFieldXY(Castro.FaceX(),Castro.FaceY()));
				}
				}
				//set kordinat dan arah hadap
				// pengencekan kordinat di lahan
				else if (arrowmotion==27)
				{arrowmode = false;
				}
			 else { 
				if (IsInRumah()) ArrowRumah(arrowmotion);
				else if (IsInLahan()) ArrowLahan(arrowmotion);
				else if (IsInToko()) ArrowToko(arrowmotion);
			}
			 //kurcaci
			TP1.setX(Kurcaci1.getPositionX()); TP1.setY(Kurcaci1.getPositionY());
			area.GetFieldwProp(0,&TP2);
			Kurcaci1.nextMove(TP1,TP2,&area);
			LCD.ChangeCharPos(1,TP1.getX(),TP1.getY(),Kurcaci1.getDirection(),Kurcaci1.getPositionX(),Kurcaci1.getPositionY());
			LCD.ChangeCharPos(0,TempX, TempY,Castro.getDirection(), Castro.getPositionX(), Castro.getPositionY());
			LCD.PrintJam(time.GetJJ(),time.GetMM());
			LCD.PrintTgl(time.GetHH(),time.GetBB());
			LCD.PrintLoc(Castro.getLocation());
			LCD.PrintKor(Castro.getLocation(), Castro.getPositionX(),Castro.getPositionY());
			LCD.PrintCua(time.GetBencana());
			LCD.PrintMus(time.GetMU());
			LCD.PrintSt(Castro.getStatus());
			LCD.PrintBuck(Castro.getMoney());
			LCD.SetODMeter(Castro.getOD());
			LCD.SetSkwMeter(Castro.getSakaw());
			LCD.PrintODSKW();
			LCD.PrintKur(area.GetStKurc(1),area.GetStKurc(2),area.GetStKurc(3));
			//LCD.PrintField(Castro.getLocation(),ar[Castro.FaceX()+1][Castro.FaceY()+1], Castro.FaceX(), Castro.FaceY(), &area);
			LCD.PrintInv(Castro.getInventory());
			Sleep(200);
		}
		 
		 
		 
		 // if (IsArrowUp(Com.GetArrow())){
			// cout<<"Ke atas";
		// }
		// else if (IsArrowRight(Com.GetArrow())){
			// cout<<"Ke kanan";
		// }
		// else if (IsArrowLeft(Com.GetArrow())){
			// cout<<"Ke kiri";
		// }
		// else if (IsArrowDown(Com.GetArrow())){
			// cout<<"Ke bawah";
		// }
		// else cout<<"salah panah";
	}
void PlayGame::ArrowRumah(int motion){
	if (motion==122){
		cout<<"exit"<<endl;
	}
	else if (motion == 120){
		SavingData();
	}
	else if (motion == 99){
		Sleeping();
	}
	else if ((motion == 119) || (motion == 87)){
		LCD.PrintGo(2000);
		Castro.Teleport(1);
		DisplayGame();
		HelpArrowMode();
	}
	else if ((motion == 105) || motion == 73){
		cout<<"inventory"<<endl;
	}
	else if ((motion == 104) || motion == 72){
		Eating();
	}
}
void PlayGame::ArrowLahan(int motion){
	int NoSlot=0;
	int jumlah=0;
	int NoKurcaci=0;
	if (motion==122){ // z
		Plowing();
		DisplayGame();
	}
	else if (motion == 120){ // x
		LCD.PrintInfo("Slot berapa = ");
		cin>>NoSlot;
		LCD.PrintInfo("jumlah = ");
		cin>>jumlah;
		PutOrSell(NoSlot, jumlah);
		DisplayGame();
	}
	else if (motion == 99){ // c
		Slashing();
		DisplayGame();
	}
	else if (motion == 118){ // v
		Watering();
		DisplayGame();
	}
	else if (motion == 98){ // v
		Harvesting();
		DisplayGame();
	}
	else if ((motion == 97) || motion == 65){ // a
		LCD.PrintInfo("Kurcaci no berapa = ");
		cin>>NoKurcaci;
		WakeingUp(NoKurcaci);
		DisplayGame();
	}
	else if ((motion == 115) || motion == 83){ //s
		LCD.PrintInfo("Kurcaci no berapa = ");
		cin>>NoKurcaci;
		SleepKurcaci(NoKurcaci);
		DisplayGame();
	}
	else if ((motion == 100) || motion == 68){ // d
		//status
	}
	else if ((motion == 113) || motion == 81){ // q
		LCD.PrintGo(2000);
		Castro.Teleport(0);
		DisplayGame();
		HelpArrowMode();	
	}
	else if ((motion == 101) || motion == 69){ // e
		LCD.PrintGo(2000);
		Castro.Teleport(2);
		DisplayGame();
		HelpArrowMode();
	}
	else if ((motion == 105) || motion == 73){ // i
		//inventory
	}
	else if ((motion == 104) || motion == 72){ // i
		Eating();
	}
}
void PlayGame::ArrowToko(int motion){
	int ID;
	int jumlah;
	int Slot;
	if (motion==122){ // z
		Buying(ID, jumlah);
	}
	else if (motion == 120){ // x
		Selling(Slot, jumlah);
	}
	else if (motion == 99){ // c
			// store
	}
	else if ((motion == 119) || (motion == 87)){
		LCD.PrintGo(2000);
		Castro.Teleport(1);
		DisplayGame();
		HelpArrowMode();
	}
	else if ((motion == 105) || (motion == 73)){
//		inventory
	}
	else if ((motion == 104) || (motion == 72)){
		Eating();
	}
}

void PlayGame::DisplayGame(){
		
	int a,b;
	int fil[8][10];
	//INISIALISASI
	LCD.SetPlayer(Castro.getPositionX(),Castro.getPositionY(),Castro.getDirection());
	area.SetAllKurc(Kurcaci1.getStatus(),Kurcaci2.getStatus(),Kurcaci3.getStatus());
	LCD.SetKurcaci1(Kurcaci1.getPositionX(),Kurcaci1.getPositionY(),Kurcaci1.getDirection());
	LCD.SetKurcaci2(Kurcaci2.getPositionX(),Kurcaci2.getPositionY(),Kurcaci2.getDirection());
	LCD.SetKurcaci3(Kurcaci3.getPositionX(), Kurcaci3.getPositionY(), Kurcaci3.getDirection());
	LCD.SetODMeter(Castro.getOD());
	LCD.SetSkwMeter(Castro.getSakaw());
	//
	area.KonvPrint(Castro.getLocation(), fil);
	LCD.PrintName(Castro.getName());
	LCD << fil;
	LCD.PrintAllFl();
	LCD.PrintAllChar(Castro.getLocation(),area.GetStKurc(1),area.GetStKurc(2),area.GetStKurc(3));
	//INFO SELESAI
	LCD.PrintJam(time.GetJJ(),time.GetMM());
	LCD.PrintTgl(time.GetHH(),time.GetBB());
	LCD.PrintLoc(Castro.getLocation());
	LCD.PrintKor(Castro.getLocation(), Castro.getPositionX(),Castro.getPositionY());
	LCD.PrintCua(time.GetBencana());
	LCD.PrintMus(time.GetMU());
	LCD.PrintName(Castro.getName());
	LCD.PrintSt(Castro.getStatus());
	LCD.PrintBuck(Castro.getMoney());
	LCD.PrintODSKW();
	LCD.PrintKur(area.GetStKurc(1),area.GetStKurc(2),area.GetStKurc(3));
	//LCD.PrintField(Castro.getLocation(),fil[Castro.FaceX()+1][Castro.FaceY()+1], Castro.FaceX(), Castro.FaceY(), &area);
	LCD.PrintInv(Castro.getInventory());

	//LCD.PrintInfoL(area.GetLFieldXY(Castro.FaceX(),Castro.FaceY()));
	LCD.Go(2,33);
	}
void PlayGame::DisplayInterface(){
	
		// int fil[6][8];
		// int i,j;
		// //inisialisasi
		// for (i = 0;i <= 5;i++) {
			// for (j = 0;j <= 7;j++) {
				// fil[i][j] = 1;
			// }
		// }
		
		// // LCD.SetJudul(3, 5, 4, 10, 2, 2, 4, "PANAS", "TERANG");
		 // LCD.SetWarna(1,15);
		
		// // //UBAH NAMA
		// // LCD.SetStrPanel(1,0,"FIDEL CASTRO");
		
		// // //UBAH STATUS
		// // LCD.SetStrPanel(1,1,"NORMAL");
		
		// // //UBAH UANG
		// // LCD.SetStrPanel(1,2,"65.000 BUCK");
		
		// // //UBAH NAMA TANAMAN
		// // LCD.SetStrPanel(2,0,"CANABIS");
		
		// LCD.ClearScr();
		// //string jud;
		// /*jud = "TT/BB            HH:MM          RUMAH< , >           MUSIM           CUACA";
		// a[1]= "COBAA"				;	b[1]= "ABISA";
		// a[2]= "AJAA"					;	b[2]= "INIA";
		// a[3]= "NIHA"					;	b[3]= "COBAA";
		// a[4]= "TESTINGA"				;	b[4]= "TRUAS";
		// a[5]= "YUHUA"				;	b[5]= "MAMPUAS";*/
		// LCD << fil;
	// LCD.PrintJudul();
	
	cout<<"\n - new <nama pemain> #"<<endl;
	cout<<" - load <nama file> #"<<endl;
	cout<<"\n***** < LOS_DROGAS > *****\n"<<endl;
		
	}
void PlayGame::HelpArrowMode(){
			LCD.ClearInfoBox();
			if (IsInRumah()){
					LCD.PrintInfoBox(1,"<Home_Arrow_Mode> ");
					LCD.PrintInfoBox(4,"< z : exit \t\t\t>");
					LCD.PrintInfoBox(5,"< x : save \t\t\t>");
					LCD.PrintInfoBox(6,"< c : sleep \t\t\t>");
					LCD.PrintInfoBox(7,"< w : teleport lahan \t>");

				}
				else if (IsInLahan()){
					LCD.PrintInfoBox(1,"<Lahan_Arrow_Mode> ");
					LCD.PrintInfoBox(4,"< z : plow \t\t v : water\t>");
					LCD.PrintInfoBox(5,"< x : put \t\t b : harvest\t>");
					LCD.PrintInfoBox(6,"< c : slash \t>");
					LCD.PrintInfoBox(7,"< q : teleport rumah \t>");
					LCD.PrintInfoBox(8,"< e : teleport toko \t>");
				}
				else if (IsInToko()){
					LCD.PrintInfoBox(1,"<Toko_Arrow_Mode> ");
					LCD.PrintInfoBox(4,"< z : buy \t>");
					LCD.PrintInfoBox(5,"< x : sell \t>");
					LCD.PrintInfoBox(6,"< c : store \t>");
					LCD.PrintInfoBox(7,"< w : teleport lahan \t>");
				}
			LCD.PrintInfoBox(2,"< Arrow Mode memperbolehkan aksi yang dilakukan melalui panah >");
			LCD.PrintInfoBox(3,"< atas/kanan/kiri/bawah) pada keyboard untuk pergerakan >");
			LCD.PrintInfoBox(9,"< i : inventory \t\t>");
			LCD.PrintInfoBox(10,"< g : makan \t\t\t>");
			LCD.PrintInfoBox(11,"< tekan tombol ESC untuk mengakhiri arrow mode ...>");

		}	
void PlayGame::HelpNormalMode(){
			LCD.ClearInfoBox();
			if (IsInRumah()){
						 LCD.PrintInfoBox(1,"Perintah yang dapat dilakukan :");
						 LCD.PrintInfoBox(2,"\t- save #");
						 LCD.PrintInfoBox(3,"\t- sleep #");
						 LCD.PrintInfoBox(4,"\t- exit #");
						 LCD.PrintInfoBox(5,"\t- teleport lahan #");
						 LCD.PrintInfoBox(6,"\t- inventory #");
						 LCD.PrintInfoBox(7,"\t- (right/left/down/up) (jumlah langkah) #");
						 LCD.PrintInfoBox(8,"\t- arrow");
						 LCD.Go(2,33);LCD.SetWarna(1,11);
						 LCD.PrintKsg(77);
						 LCD.Go(2,33);
						 cout << "Rumah > ";
				}
				else if (IsInLahan()){
						 LCD.PrintInfoBox(1,"Perintah yang dapat dilakukan :");
						 LCD.PrintInfoBox(2,"\t- plow #");
						 LCD.PrintInfoBox(3,"\t- put #");
						 LCD.PrintInfoBox(4,"\t- slash #");
						 LCD.PrintInfoBox(5,"\t- harvest #");
						 LCD.PrintInfoBox(6,"\t- water #");
						 LCD.PrintInfoBox(7,"\t- wake_up (nomor kurcaci) #");
						 LCD.PrintInfoBox(8,"\t- status kurcaci #");
						 LCD.PrintInfoBox(9,"\t- teleport (rumah/toko) #");
						 LCD.PrintInfoBox(10,"\t- inventory #");
						 LCD.PrintInfoBox(11,"\t- arrow");
						 LCD.Go(2,33);LCD.SetWarna(1,11);
						 LCD.PrintKsg(77);
						 LCD.Go(2,33);
						 cout<<"Lahan > ";
				}
				else if (IsInToko()){
						 LCD.PrintInfoBox(1,"Perintah yang dapat dilakukan :");
						 LCD.PrintInfoBox(2,"\t- store #");
						 LCD.PrintInfoBox(3,"\t- sell #");
						 LCD.PrintInfoBox(4,"\t- buy #");
						 LCD.PrintInfoBox(5,"\t- inventory #");
						 LCD.PrintInfoBox(6,"\t- teleport lahan #");
						 LCD.PrintInfoBox(7,"\t- arrow");
						 LCD.Go(2,33);LCD.SetWarna(1,11);
						 LCD.PrintKsg(77);
						 LCD.Go(2,33);
						 cout << "Toko > ";
				}
		}
void PlayGame::NewData(string nama){
	time=waktu(1,1,1,4,0); // waktu di set ke tanggal awal
	time.bencana(); // bencana di set
	Castro.setMoney(50); // uang pertama
	Castro.setName(nama); // pengesetan nama

}
void PlayGame::Sleeping(){ // method untuk perintah sleep
	time.sleep(); // method waktu tidur
	 LCD.PrintInfo("Sleeping()");
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
	area.SyncAll();
	Castro.Teleport(0);
	LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
	StartGame();
	}	
}
void PlayGame::Selling(int slot, int jumlah){
	// Kamus
	int uang;
	// Algoritma
	if ((slot <4) && (slot>0)){ // jika slot antara 1 sampai 3
		if ((Castro.getInventory())->SlotIsi(slot)){ // jika slot di inventory ada isinya
			if ((Castro.getInventory())->adrSlotIsi(slot)->getwhatisthis()==1){ // jika isi inventory benar-benar hasil panen
				if (jumlah>0){ // validasi jumlah
					if (Castro.getInventory()->getAmount(slot)>=jumlah){ // jika jumlah yang diminta sesuai dengan jumlah barang di inventory
						uang = InfoTanaman.getDaftarInfo((Castro.getInventory())->adrSlotIsi(slot)->getID() -1,1)*jumlah; // jumlah uang yang didapat
						(Castro.getInventory())->remItem(slot, jumlah); // pengurangan item
						Castro.setMoney(Castro.getMoney()+uang); // penambahan uang
					}
					else LCD.PrintInfo("jumlah barang tidak mencukupi");
				}
				else LCD.PrintInfo("jumlah barang tidak valid");
			}
			else LCD.PrintInfo("item bukanlah hasil panen");
		}
		else LCD.PrintInfo("tidak ada item di dalam slot");
	}
	else LCD.PrintInfo("Nomor Slot tidak terdefinisi");
	
}
void PlayGame::Buying(int ID, int jumlah){
	int uang= InfoTanaman.getDaftarInfo(ID-1,0)*jumlah;
	if (Castro.getMoney()>=uang){ // jika uangnya mencukupi
		if (ID==1){
			Ganja *ganja = new Ganja;
			(Castro.getInventory())->addItem(ganja, jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
		}
		else if (ID==2){
			Opium *opium = new Opium;
			(Castro.getInventory())->addItem(opium, jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
		}
		else if (ID==3){
			Coca *coca = new Coca;
			(Castro.getInventory())->addItem(coca, jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
		}
		else if (ID==4){
			Tobacco *tobacco = new Tobacco;
			(Castro.getInventory())->addItem(tobacco, jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
							}
		else if (ID==5){
			Anggur *anggur = new Anggur;
			(Castro.getInventory())->addItem(anggur,jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
		}
		else if (ID==6){
			Mushroom *mushroom = new Mushroom;
			(Castro.getInventory())->addItem(mushroom, jumlah);
			/*cout<<"\njumlah = "<<(Castro.getInventory())->getAmount1();
			cout<<"\nID = "<<((Castro.getInventory())->getSlot1())->getID();
			Castro.setMoney(Castro.getMoney()-uang );
			cout<<"\nMoney = "<<Castro.getMoney();getch();*/
		}
		else {LCD.PrintInfo("Nama bibit salah");}
	}
	else {LCD.PrintInfo("Uang tidak cukup");}
}

int PlayGame::IsInLahan(){
		return (Castro.getLocation()==1);
	}
	int PlayGame::IsInToko(){
		return (Castro.getLocation()==2);
	}
	
int PlayGame::IsInRumah(){
		return (Castro.getLocation()==0);
	}

void PlayGame::DataGame(){ 
	LCD.PrintTemplate();
	Castro.setPosition(0,1);
	Castro.setLocation(0);
	Castro.setDirection(3);

}
void PlayGame::tambahwaktu(){
	time=waktu(1,1,1,4,0);
	time.initBencana();
	time.bencana();
	int i=1;
	char a;
	while(i < 200){
		time.penambahWktNormal();
		if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
			area.SyncAll();
			Castro.Teleport(0);
			LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
			StartGame();
		}
		time.printWaktu();
		cout << "\t\t" <<time.isHujan() << time.isTopan()  << time.isRazia() << time.isCropCircle() << endl;
		i=i+1;
	}
	cout << "ch = " << time.GetHujan() << endl;
	cout << "cr = " << time.GetRazia() << endl;
	cout << "ct = " << time.GetTopan() << endl;
	cout << "cb = " << time.GetCC() << endl;
	}
void PlayGame::SavingData(){
	LCD.PrintInfo("IO.SaveGame()");
	IO.SaveFarmE(&Castro, &time, &area);
}
void PlayGame::Plowing(){
	time.penambahWktNormal();
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
	area.SyncAll();
	Castro.Teleport(0);
	LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
	StartGame();
	}		
	(Castro.Plow(&area));	
}
void PlayGame::PutOrSell(int NoSlot, int Jumlah){
	time.penambahWktNormal();// put(); ->>> kerja
	//cout << endl << area.GetLFieldXY(Castro.FaceX(), Castro.FaceY())->GetCond() << endl;
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
		area.SyncAll();
		Castro.Teleport(0);
		}
	if (Castro.getInventory()->SlotIsi(NoSlot)) {
	(Castro.Put(&area,Castro.getInventory()->getSlot(NoSlot)->getID()));
	} 
	//cout << endl << area.GetLFieldXY(Castro.FaceX(), Castro.FaceY())->GetCond() << endl;

}
void PlayGame::Slashing(){
	time.penambahWktNormal();// IsKosong(); CleanArea(); ->>> kerja
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
		area.SyncAll();
		Castro.Teleport(0);
		LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
		StartGame();
	}// IsKosong(); CleanArea(); ->>> kerja
		(Castro.Slash(&area));	

}
void PlayGame::Watering(){
	time.penambahWktNormal();// IsPlantable(); IsWatered(); WaterArea(); ->>> kerja
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
		area.SyncAll();
		Castro.Teleport(0);
		LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
		StartGame();
	}// IsKosong(); CleanArea(); ->>> kerja
		(Castro.Water(&area));	
			
}
void PlayGame::Harvesting(){
	time.penambahWktNormal();// IsPanen(); ->>>> kerja
	if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
		area.SyncAll();
		Castro.Teleport(0);
		LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
		StartGame();
	}// IsKosong(); CleanArea(); ->>> kerja

	(Castro.Harvest(&area));	
		
}
void PlayGame::WakeingUp(int NoKurcaci){
				LCD.PrintInfo("SetKurcaciOn...");
					if (NoKurcaci==1){
						Kurcaci1.setStatus(1);
						tujuan.setX(1);
						tujuan.setY(2);
						awal.setX(5);
						awal.setY(3);
						}
					else if (NoKurcaci ==2)
						Kurcaci2.setStatus(1);
					else if (NoKurcaci == 3)
						Kurcaci3.setStatus(1);
						// setkurcaci on
				// method gerak AI

}
void PlayGame::SleepKurcaci(int NoKurcaci){
					LCD.PrintInfo("SetKurcaciOff...");
					NoKurcaci = atoi(Com.ArrayOfCommand[2].c_str());
					if (NoKurcaci==1)
						Kurcaci1.setStatus(0);
					else if (NoKurcaci ==2)
						Kurcaci2.setStatus(0);
					else if (NoKurcaci == 3)
						Kurcaci3.setStatus(0);
					//set kurcaci belum ada

}
void PlayGame::Eating(){
				time.penambahWktNormal();
				if ((time.GetJJ() == 4) && (time.GetMM() == 0)) {
					area.SyncAll();
					Castro.Teleport(0);
					LCD.Go(2,33);LCD.SetWarna(1,11);LCD.StdStr("Ngantuk....zZzZzz",78);
					StartGame();
				}// IsKosong(); CleanArea(); ->>> kerja

}
void PlayGame::ViewStore(){
					LCD.ClearScr();
					cout << "INFORMASI DAFTAR HARGA BARANG DI TOKO..." << endl;
					InfoTanaman.showHargaBibit();
					InfoTanaman.showHargaPanen();
					cout<<"Tekan Enter untuk kembali ke toko..."<<endl;
					getch();
					LCD.PrintTemplate();
					DisplayGame();

}
